//定义懒加载插件
import { useIntersectionObserver } from '@vueuse/core'
export const lazyPlugin = {
  install (app) {
    //定义全局指令
    app.directive('img-lazy',{
      mounted (el,binding) {
        //console.log(el,binding.value)
        const {stop} = useIntersectionObserver(//监听页面中某个元素出现的否
          el,
          ([{ isIntersecting }]) => {
            //console.log(isIntersecting)
            if(isIntersecting){
              //进入了视口区
              el.src = binding.value
              stop()
            }
          }
        )
      }
    })
  }
}
